import { getFriendLists, getFriendChatRecord } from "@/service/chat"
import router from "@/router"
import CacheLocal from "@/utils/cacheLocal"
import { ActionTree } from "vuex"
import { IChatState } from "./types"
import { IState } from "@/store/types"
const actions: ActionTree<IChatState, IState> = {
  //获取好友列表
  async acGetFriendLists({ commit }) {
    // const { list } = await (await getFriendLists()).data;
    const { list } = await (await getFriendLists()).data
    console.log("list:", list)

    commit("saveChatFriendList", list)
  },

  //获取当前聊天内容
  async getCurrentChat(
    { commit },
    payload: {
      userId: number
      friendId: number
    }
  ) {
    const { records } = (await getFriendChatRecord(payload)).data
    commit("changeCurrentChat", records)
  }
}

export type IChatActions = {
  moduleChat: {
    acGetFriendLists: () => any
    getCurrentChat: () => any
  }
}

export { actions }
